import GyroApi from '@/api/gyro';

export default {
  methods: {
	doRefresh: function () {
	  this.$confirm('确定刷新设备, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.refresh().then((res) => {
		  this.$message({type: 'success', message: '刷新命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doConfig: function (setting) {
	  this.$confirm('确定配置设备, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.config(setting).then((res) => {
		  this.$message({type: 'success', message: '配置命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doStartGather: function () {
	  this.$confirm('确定开始采集, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.gather().then((res) => {
		  this.$message({type: 'success', message: '开始采集命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doStopGather: function () {
	  this.$confirm('确定停止采集, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.ungather().then((res) => {
		  this.$message({type: 'success', message: '停止采集命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doStartUpload: function () {
	  this.$confirm('请识别到 MAC 后再开始上传数据, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.upload().then((res) => {
		  this.$message({type: 'success', message: '开始上传命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doStopUpload: function () {
	  this.$confirm('确定停止上传, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.unupload().then((res) => {
		  this.$message({type: 'success', message: '停止上传命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doFlush: function () {
	  this.$confirm('确定清除数据, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.flush().then((res) => {
		  this.$message({type: 'success', message: '清除数据命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doReboot: function () {
	  this.$confirm('确定重启设备, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.reboot().then((res) => {
		  this.$message({type: 'success', message: '重启设备命令发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
	doClose: function () {
	  this.$confirm('确定关闭设备, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	  }).then(() => {
		GyroApi.close().then((res) => {
		  this.$message({type: 'success', message: '关闭设备发送成功!'});
		})
	  }).catch(() => {
		this.$message({type: 'success', message: '操作失败!'});
	  });
	},
  }
};